package org.xcorpio.java8.chapter05;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.xcorpio.java8.common.Data;

public class Reducing {

    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 4, 6);
        Integer sum = numbers.stream().reduce(0, (a, b) -> a + b);
        System.out.println("sum:" + sum);
        System.out.println("sum:" + numbers.stream().reduce(0, Integer::sum));
        System.out.println("sum:" + numbers.stream().reduce((a, b) -> a + b));
        System.out.println("mul:" + numbers.stream().reduce(1, (a, b) -> a * b));
        System.out.println("max:" + numbers.stream().reduce(Integer::max));
        System.out.println("min:" + numbers.stream().reduce(Integer::min));
        Optional<Integer> count = Data.Menu.stream()
                             .map(d -> 1)
                             .reduce((a, b) -> a + b);
        System.out.println(count);
    }
}
